/* -----------------
* brief
* 1. this is code gen by tools
* 2. mvc code are driver by the model defined with the same filename,
	 for example:
	 there is a Xmodel struct define in xmodel.go file, after the script run (lego model-mvc module_name xmodel)
     it will auto create the code under the module's path
	 m --> xmodel.go
	 v --> view
	 c --> xmodel_ctrl
* 3. you should modify this code if it doesn't satisfy your purpose
*/

package controller

import (
	UserService "saas_sys_base/modules/user/service"
)


type UserApiCtrl struct {
	UserService UserService.UserService
	TenantUserService UserService.TenantUserService
}

func init() {
	vc := new(UserApiCtrl)
	_ctrlList = append(_ctrlList, vc)
}

func (vc *UserApiCtrl) CtrlInfo() string {
	return "ApiCtrl"
}

func (vc *UserApiCtrl) RoutInit() {

	// 3. 商户端小程序登陆获取token
	//lego.APIPOST("/api/tenant/user/login", vc.TenantUserLogin, false)

	// 4. 获取商户信息
	//lego.APIPOST("/api/tenant/user/profile", vc.TenantUserProfile, false)
}


//商户端
/*
func (vc *UserApiCtrl) TenantUserLogin(ctx *fasthttp.RequestCtx) {
	ctxExt := lego.RequestCtxExtent{ctx}
	response := make(map[string]interface{})
	data := make(map[string]interface{})

	type Resp struct {
		*UserService.LoginUser
		Token string
	}
	code := 0
	msg := "success"

	for {
		//rawcode := string(ctxExt.Peek("code"))
		//tid, _ := utils.StringToInt64(string(ctxExt.Peek("tid"))) //tenant id
		//shareid := string(ctx.FormValue("shareid")) // 谁邀请的
		//rawData := string(ctx.PostArgs().Peek("rawData"))

		type Request struct {
			Code   string
			Tid    int64
			AppId int64 //内部app id, internal app id
		}
		var req Request
		requestByte := ctxExt.PostBody()
		err := json.Unmarshal(requestByte, &req)

		//fmt.Println(rawData)
		if err != nil {
			code = 100
			msg = err.Error()
			break
		}

		if len(req.Code) <= 0 {
			code = 100
			msg = "参数错误"
			break
		}

		who := common.NewWho(req.Tid, req.AppId, 0)
		User, tokenString, err := vc.TenantUserService.UserLogin(*who, req.Code)
		if err != nil {
			code = 100
			msg = err.Error()
			break
		}

		resp := &Resp{}
		resp.LoginUser = User
		resp.Token = tokenString

		data["token"] = tokenString
		response["data"] = resp
		break
	}

	response["code"] = code
	response["msg"] = msg
	ctxExt.JSON(200, response)
	return
}*/

/* 获取token
* params:
  ---
*/
/*
func (vc *UserApiCtrl) TenantUserProfile(ctx *fasthttp.RequestCtx) {
	ctxExt := lego.RequestCtxExtent{ctx}
	response := make(map[string]interface{})
	//data := make(map[string]interface{})

	code := 0
	msg := "success"

	for {
		//rawcode := string(ctxExt.Peek("code"))
		//tid, _ := utils.StringToInt64(string(ctxExt.Peek("tid"))) //tenant id
		//shareid := string(ctx.FormValue("shareid")) // 谁邀请的
		//rawData := string(ctx.PostArgs().Peek("rawData"))

		type Request struct {
			Token   string
			Timestamp string
		}
		var req Request
		requestByte := ctxExt.PostBody()
		json.Unmarshal(requestByte, &req)


		//fmt.Println("dengjinL", req.Token)
		User, err := vc.TenantUserService.CheckToken(&ctxExt, req.Token, req.Timestamp)
		if err != nil {
			code = 100
			msg = err.Error()
			break
		}

		response["data"] = User
		break
	}

	response["code"] = code
	response["msg"] = msg
	ctxExt.JSON(200, response)
	return
}*/
